% !TeX program = xelatex
% !TeX encoding = UTF-8
\ProvidesClass{CourPR}[2022/02/15]
\LoadClass[a4paper,twoside]{article}%
%

\RequirePackage{kvoptions}
\RequirePackage{xifthen}
\SetupKeyvalOptions{
	family = @hainnucourse,
	prefix = @hainnucourse@
}
\DeclareBoolOption[true]{AbstractOn}       % automatically creates \ifmypackage@fullpage
\DeclareComplementaryOption{AbstractOff}{AbstractOn}  % automatically inverses the former
\DeclareBoolOption[true]{single}       % automatically creates \ifmypackage@fullpage
\DeclareComplementaryOption{teamwork}{single}  % automatically inverses the former
\ProcessKeyvalOptions*{}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 字体设定
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RequirePackage[CJKmath=true]{xeCJK}%
\xeCJKsetup{AutoFakeSlant={true},AutoFakeBold={true}}		%设置加粗和斜体
\usepackage{fontspec}


\setmainfont{Times New Roman}  %默认英文字体.serif是有衬线字体sans serif无衬线字体
\setmonofont{Consolas}
\setCJKmainfont[ItalicFont={KaiTi}, BoldFont={SimHei}]{宋体}%衬线字体 缺省中文字体为
%\setCJKmainfont[ItalicFont={AR PL UKai CN}, BoldFont={SimHei}]{宋体}%Linux
\setCJKsansfont{hei}
\punctstyle{hangmobanjiao}


\setCJKfamilyfont{song}{SimSun}%
\setCJKfamilyfont{kai}{KaiTi}%
\newcommand*{\kaiti}{\CJKfamily{kai}}%
\setCJKfamilyfont{fsong}{FangSong}%
\newcommand*{\fsong}{\CJKfamily{fsong}}%
\newcommand{\ktgb}{\CJKfamily{ktgb}}
\setCJKfamilyfont{hei}{SimHei}          


\RequirePackage[T1]{fontenc} % 保证英文字体加粗有效


\RequirePackage{ctex}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 封面页命令与参数设定
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\Org}[1]{\def\Organization{#1}}         %学习机构/单位
\newcommand{\OrgLogoIm}[1]{\def\OrgLogoImageName{#1}} %学习机构/单位Logo
\newcommand{\Leader}[1]{\def\LeaderName{#1}}   	%学生姓名
\newcommand{\StuName}[1]{\def\StudentName{#1}}   	%学生姓名
\newcommand{\StuID}[1]{\def\StudentID{#1}}   	%学号
\newcommand{\MemName}[1]{\def\MemberName{#1}}   	%学生姓名
\newcommand{\Group}[1]{\def\GroupID{#1}}       		%组别
\newcommand{\Year}[1]{\def\CourseYear{#1}}   		%课程年份
\newcommand{\Major}[1]{\def\MajorName{#1}}       	%学生专业
\newcommand{\Class}[1]{\def\ClassID{#1}}		 	%学生年级
\newcommand{\Depart}[1]{\def\Department{#1}}        %单位里的二级部门
\newcommand{\Course}[1]{\def\CourseName{#1}}        %课程名称
\newcommand{\SubmitTime}[1]{\def\SubmitionTime{#1}} %完成时间
\newcommand{\ProfName}[1]{\def\ProfessorName{#1}}   %指导教师姓名
\newcommand{\AcadTitle}[1]{\def\AcademicTitle{#1}}  %教师头衔
\newcommand{\cnTitle}[1]{\def\ChineseTitle{#1}}     % 论文名称
\newcommand{\enTitle}[1]{\def\EnglishTitle{#1}}     % 论文名称
\newcommand{\StudType}[1]{\def\StudentType{#1}}     % 学生类型
\newcommand{\TaskType}[1]{\def\WorkFor{#1}}
\newcommand{\DocType}[1]{\def\DocumentType{#1}} 		% 文章类型

\newcommand{\CourID}[1]{\def\CourseID{#1}} 		% 课程编号
\newcommand{\DocID}[1]{\def\DocumentID{#1}} 		% 文档编号
\newcommand{\Ver}[1]{\def\Version{#1}} 		% 文档版本


\renewcommand{\today}{\kaiti \number\year 年\number \month 月\number\day 日}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 常用设定
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\hnnu@underline[2][6em]{\hskip1pt\underline{\hb@xt@ #1{\hss#2\hss}}\hskip3pt}
\usepackage{newclude}
\RequirePackage{setspace}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 其他设定
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RequirePackage{diagbox}

% 数学字体设定
\RequirePackage{amsmath,amssymb,amsfonts}%
\RequirePackage{pifont}%

% 列表设定
\RequirePackage{enumerate}
\RequirePackage{enumitem}
\newlist{renumerate}{enumerate}{3}
\setlist[renumerate]{label=\protect\ding{\value*},start=172}


% 插图设定
\RequirePackage{graphics}%
\RequirePackage{graphicx}%
\RequirePackage[rgb]{xcolor}%
\RequirePackage{subfigure}%
\RequirePackage{caption}%
\RequirePackage{float}%
\RequirePackage{epsfig}%

% 表格设定
\RequirePackage{multirow}%
\RequirePackage{makecell}%
\RequirePackage{array}%
\RequirePackage{booktabs}%
\RequirePackage{longtable}%
\RequirePackage{tabularx}%
\def\tabularxcolumn#1{m{#1}}

% 超链接设定
\RequirePackage{url}%
%\RequirePackage{cite}%
\RequirePackage[colorlinks,linkcolor=blue]{hyperref}%

% 页面布局
\RequirePackage{fancyhdr}%
\RequirePackage{geometry}%
\geometry{top=1in,bottom=1in,left=1.1in,right=1in}%
\fancypagestyle{mainFancy}{
    \fancyhf{}
\lfoot{\Organization}
\rfoot{手写签名:\underline{\makebox[20mm]{ }}}
\renewcommand\footrulewidth{0.2pt}
\fancyhead[CE]{\DocumentType 名称：\textbf{\ChineseTitle}}
\fancyhead[LO]{{\StudentType}---{\CourseName}---{\WorkFor \DocumentType}}
\if@hainnucourse@single
\fancyhead[RO]{文档编号:\CourseID-\CourseYear-\DocumentID-\StudentID-V\Version}
\else
\fancyhead[RO]{文档编号:\CourseID-\CourseYear-\DocumentID-\GroupID-V\Version}
\fi
\fancyfoot[C]{\thepage}
}



%代码环境
\RequirePackage{listings} %插入代码

%Tikz绘图工具包
\RequirePackage{tikz}
\usetikzlibrary{arrows,math,calc,topaths,positioning,automata,shapes,chains}
\RequirePackage{pgfplots}
\RequirePackage{tikz-3dplot}
\usetikzlibrary{backgrounds,mindmap}

\pgfplotsset{compat=1.14}
\tikzset{>=latex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 英文名称汉化
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand{\contentsname}{\zihao{3} 目\quad 录}
\renewcommand{\abstractname}{\zihao{3} 摘\quad 要}
\renewcommand{\refname}{\centering 参考文献}
\renewcommand{\tablename}{{\kaiti 表}}
\renewcommand{\figurename}{{\kaiti 图}}
\renewcommand{\lstlistingname}{{\kaiti 代码}}
\renewcommand{\appendixname}{{\kaiti 附录}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 缩进及行间距
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\parindent}{2em} %重新定义缩进长度
%\setlength{\baselineskip}{20pt}  %定义行间距
%%\renewcommand{\baselinestretch}{1.1} %定义行间距

\setlength{\parskip}{6pt}  %定义段间距

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 声明页
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\hnnu@declaretext}{%
	本人声明所呈交的{\WorkFor}{\DocumentType}是本人在导师指导下进行的研究工作及取得的研究成果，
	除了文中特别加以标注和致谢的地方外，本论文中没有抄袭他人研究成果和伪造数据等行为 。与我一同工作的同志对本研究所做的任何贡献均已在{\WorkFor}{\DocumentType}中作了明确的说明并表示谢意。
}
\newcommand{\hnnu@authorization}{%
	{\Organization}有权保留并向国家有关部门或机构送交{\WorkFor}{\DocumentType}的复印件和磁盘，
	允许{\WorkFor}{\DocumentType}被查阅和借阅。本人授权{\Organization}可以将本{\WorkFor}{\DocumentType}的全部或部分内容编入有关数据库进行检索，可以采用影印、缩印或其他复印手段保存、汇编{\WorkFor}{\DocumentType}。
}

\newcommand\make@authorization{%
	\pagenumbering{roman}
	\cleardoublepage
%	\thispagestyle{empty}
	\begin{center}\zihao{3}\bfseries{\heiti{{\StudentType}{\WorkFor}{\DocumentType}原创性声明}}\end{center}
	\vspace{28pt}
	\par\fsong{\hnnu@declaretext}\par
	\vskip1.0cm
	{\begin{tabular}{p{6cm}p{6cm}}
			{\DocumentType}作者签名：\hnnu@underline{} & 日期：\hnnu@underline{}
	\end{tabular}}
	\vskip2.0cm
	\begin{center}\zihao{3}\bfseries{\heiti{{\StudentType}{\WorkFor}{\DocumentType}使用授权声明}}\end{center}
	\vspace{28pt}
	\par\fsong{\hnnu@authorization}\par
	\vskip1.0cm
	{\renewcommand{\arraystretch}{2.0}%行高
		\begin{tabular}{p{6cm}p{6cm}}
			{\DocumentType}作者签名：\hnnu@underline{} & 日期：\hnnu@underline{} \\
			指导教师签名：\hnnu@underline{} & 日期：\hnnu@underline{}
	\end{tabular}}
	\clearpage
	\songti
	\if@twoside
	\thispagestyle{empty}
	\cleardoublepage
	\fi
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 设置标题字体大小
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{titlesec}
\titleformat{\section}{\zihao{3}\bfseries}{\bfseries\arabic{section}}{0.5em}{}
\titleformat{\subsection}{\zihao{-3}\bfseries}{\bfseries\arabic{section}.\bfseries\arabic{subsection}}{0.5em}{}
\titleformat{\subsubsection}{\zihao{4}\bfseries}{\bfseries\arabic{section}.\bfseries\arabic{subsection}.\zihao{-4}\bfseries\arabic{subsubsection}}{0.5em}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% maketitle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\maketitle{%
	\makeheader
	\make@authorization
	\pagenumbering{Roman}
	\linespread{1.1}{
		\def\contentsname{
			\begin{center}
				\zihao{2}{\kaiti 目\hspace{42pt}录}
		\end{center}}
		\zihao{4}
		\tableofcontents}
	\clearpage
	\thispagestyle{empty}
	\if@hainnucourse@AbstractOn
	\make@cntitle
	\make@entitle
	\else
	\fi
	\pagenumbering{arabic}
	\setcounter{page}{0}
	\pagestyle{mainFancy}
}

\newcommand{\makeheader}{
	
	\zihao{-4}\songti
	\begin{titlepage}
		\centering
		\includegraphics[height=7.00cm]{logoimage/\OrgLogoImageName}\\
%		\vspace*{0.5cm}
		\zihao{1}{\heiti{{\renewcommand{\CJKglue}{\hskip 12pt}\StudentType \WorkFor \DocumentType}}}\\
		\vspace*{1cm}
		{\zihao{-2}{\textbf{\ChineseTitle}}}
		\vskip 0.5cm
		\fontsize{18pt}\baselineskip
		\title{\ChineseTitle}
		\vskip 0.1cm
			\makebox[3em][s]{\zihao{4} {\heiti 课程名称}：} 
			\underline{\makebox[65mm][c]{\zihao{4}  \CourseName}}\\
			\vskip -0.2cm
			\if@hainnucourse@single
			\makebox[3em][s]{\zihao{4} {\heiti 姓名}：}
			\underline{\makebox[65mm][c]{\zihao{4}  \StudentName}}\\
			\vskip -0.2cm
			\makebox[3em][s]{\zihao{4} {\heiti 学号}：}
			\underline{\makebox[65mm][c]{\zihao{4}  \StudentID}}\\
			\vskip -0.2cm
			\else
			{\makebox[3em][s]{\zihao{4} {\heiti 组长}：} 
			\underline{\makebox[65mm][c]{\zihao{4}  \LeaderName}}\\
			\vskip 0.3cm
			\makebox[3em][s]{\zihao{4} {\heiti 组员}：}
			\underline{\makebox[65mm][c]{\zihao{4}  \begin{tabular}{c}
						\MemberName					\end{tabular}}}\\
			\vskip 0.5cm}
			\fi
			\makebox[3em][s]{\zihao{4} {\heiti 学院}：} 
			\underline{\makebox[65mm][c]{\zihao{4}  \Department}}\\
			\vskip -0.2cm
			\makebox[3em][s]{\zihao{4} {\heiti 专业}：} 
			\underline{\makebox[65mm][c]{\zihao{4}  \MajorName}}\\
			\vskip -0.2cm
			\makebox[3em][s]{\zihao{4} {\heiti 班级}：} 
			\underline{\makebox[65mm][c]{\zihao{4} {\ClassID}}}\\
			\vskip -0.2cm
			\makebox[3em][s]{\zihao{4} {\heiti 指导教师}：} 
			\underline{\makebox[65mm][c]{\zihao{4}  \ProfessorName~~\AcademicTitle}}\\
			\vskip -0.2cm
			\makebox[3em][s]{\zihao{4} {\heiti \DocumentType 版本}：} 
			\underline{\makebox[65mm][c]{\zihao{4}  \SubmitionTime~~第\Version 版}}\\
			
	\end{titlepage}
	\clearpage
	\songti
	\if@twoside
	\thispagestyle{empty}
	\cleardoublepage
	\fi
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 中英文标题与摘要等
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\cnAuthor}[1]{\def\ChineseAuthor{#1}} % 中文作者
\newcommand{\enAuthor}[1]{\def\EnglishAuthor{#1}} % 英文作者
\newcommand{\cnInst}[1]{\def\ChineseInstitution{#1}} % 作者单位
\newcommand{\enInst}[1]{\def\EnglishInstitution{#1}} % 作者单位
\newcommand{\cnAbst}[1]{\def\ChineseAbstract{#1}} % 中文摘要
\newcommand{\enAbst}[1]{\def\EnglishAbstract{#1}} % 英文摘要
\newcommand{\cnKeyword}[1]{\def\ChineseKeyword{#1}} % 中文关键词
\newcommand{\enKeyword}[1]{\def\EnglishKeyword{#1}} % 英文关键词
\newcommand{\enProfName}[1]{\def\EnglishProfessorName{#1}}   %指导教师姓名
\newcommand{\enAcadTitle}[1]{\def\EnglishAcademicTitle{#1}}  %教师头衔

\RequirePackage[runin]{abstract}
\renewcommand{\abstractnamefont}{\zihao{5}\fsong\textbf}
\renewcommand{\abstracttextfont}{\zihao{5}\fsong}

\setlength{\absleftindent}{0pt}
\setlength{\absrightindent}{0pt}
\setlength{\abstitleskip}{0em}
\abslabeldelim{： }

\newcommand{\make@cnabstract}{%
	\renewcommand{\abstractname}{摘\quad 要}
	\begin{abstract}
		\ChineseAbstract
		\par \textbf{\fsong{关键词：~}} \fsong \ChineseKeyword
	\end{abstract}
}

\newcommand{\make@enabstract}{%
	\renewcommand{\abstractname}{\textbf{Abstract}}
	\begin{abstract}
		\EnglishAbstract
		\par \textbf{Keywords:~}\EnglishKeyword
	\end{abstract}
}

\newcommand{\make@cntitle}{%
	\begin{center}
		\zihao{3}{\textbf{\ChineseTitle}}\\
		\vspace{0.5cm}
		\zihao{4}{\fsong 作者: \ChineseAuthor\quad 指导教师: \ProfessorName \quad \AcademicTitle}\\
		\zihao{-4}{(\ChineseInstitution)}
	\end{center}
	\make@cnabstract
}

\newcommand{\make@entitle}{%
	\begin{center}
		\zihao{3}{\textbf{\EnglishTitle}}\\
		\zihao{-4}{Author: \EnglishAuthor \quad 
		           Supervisor: \EnglishAcademicTitle~ \EnglishProfessorName}\\
		\zihao{-4}{(\EnglishInstitution)}
	\end{center}
	\make@enabstract
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 目录
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{titletoc}

\titlecontents{section}[0em]
{\vspace{1bp} \zihao{4} \bfseries}
{\thecontentslabel\hspace*{0.5em}}
{}
{\titlerule*[0.5pc]{$\cdot$}\contentspage}

\titlecontents{subsection}[2em]%原来是2.3
{\vspace{1bp} \zihao{4} \bfseries}
{\thecontentslabel\hspace*{0.5em}}
{}
{\titlerule*[0.5pc]{$\cdot$}\contentspage}

\titlecontents{subsubsection}[4em]%原来是2.3
{\vspace{1bp} \zihao{4} \bfseries}
{\thecontentslabel\hspace*{0.5em}}
{}
{\titlerule*[0.5pc]{$\cdot$}\contentspage}


%参考文献按照国家标准GB/T-7714指定的格式自动生成
\RequirePackage{gbt7714}



% 文档修改历史记录
\makeatletter 
\newcommand{\EditHistory}{\def\@body{}\@stepone}
\newcommand\@stepone{\@ifnextchar\StopHistory{}{\@steptwo}}
\newcommand\@steptwo[4]%
{\expandafter\def\expandafter\@body\expandafter{\@body #1 & #2 & #3 & #4 \\ \hline}%
	\@stepone
}
\newcommand\StopHistory
{\vspace{-1em}
	\noindent
	\begin{center}
		\begin{tabularx}{\textwidth}{|>{\hsize=.1\hsize}X|>{\hsize=.63\hsize}X|>{\hsize=.12\hsize}X|>{\hsize=.15\hsize}X|} \hline
			{\heiti{版本号}} & {\heiti{修改内容}} & {\heiti{修改人}} & {\heiti{修改日期}}\\ \hline
			\@body
		\end{tabularx}%
	\end{center}
}
\makeatother


% 文档审阅历史记录
\makeatletter 
\newcommand{\ProofRead}{\def\@body{}\@proofstepone}
\newcommand\@proofstepone{\@ifnextchar\StopProof{}{\@proofsteptwo}}
\newcommand\@proofsteptwo[4]%
{\expandafter\def\expandafter\@body\expandafter{\@body #1 & #2 & #3 & #4 \\ \hline}%
	\@proofstepone
}
\newcommand\StopProof
{\noindent
	\vfill
	\begin{center}
		\begin{tabularx}{\textwidth}{|>{\hsize=.1\hsize}X|>{\hsize=.61\hsize}X|>{\hsize=.14\hsize}X|>{\hsize=.15\hsize}X|} \hline
			{\heiti{版本号}} & {\heiti{审阅意见}} & {\heiti{审阅人}} & {\heiti{审阅日期}}\\ \hline
			\@body
		\end{tabularx}%
	\end{center}
	\vfill
}
\makeatother

